package gov.child.entities.po;

import gov.child.entities.vo.annotation.Alias;
import gov.child.entities.vo.annotation.IgnoreField;

import javax.persistence.*;

/**
 * @author fzh
 * @since 2017/9/16
 */
@Entity
@Table(name = "admin", schema = "gov_c")
public class EAdmin {
    @Alias("adminId")
    private Integer id;
    private Integer deptId;
    private String name;
    private String phone;
    private String username;
    @IgnoreField
    private String password;
    @IgnoreField
    private EDepartment deptByDeptId;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id", nullable = false)
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Basic
    @Column(name = "dept_id", nullable = false)
    public Integer getDeptId() {
        return deptId;
    }

    public void setDeptId(Integer deptId) {
        this.deptId = deptId;
    }

    @Basic
    @Column(name = "name", nullable = false, length = 8)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Basic
    @Column(name = "phone", nullable = false, length = 13)
    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    @Column(name = "username", nullable = false, length = 20)
    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    @Basic
    @Column(name = "password", nullable = false, length = 32)
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        EAdmin eAdmin = (EAdmin) o;

        if (id != null ? !id.equals(eAdmin.id) : eAdmin.id != null) return false;
        if (deptId != null ? !deptId.equals(eAdmin.deptId) : eAdmin.deptId != null) return false;
        if (name != null ? !name.equals(eAdmin.name) : eAdmin.name != null) return false;
        if (phone != null ? !phone.equals(eAdmin.phone) : eAdmin.phone != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = id != null ? id.hashCode() : 0;
        result = 31 * result + (deptId != null ? deptId.hashCode() : 0);
        result = 31 * result + (name != null ? name.hashCode() : 0);
        result = 31 * result + (phone != null ? phone.hashCode() : 0);
        return result;
    }

    @ManyToOne
    @JoinColumn(name = "dept_id", referencedColumnName = "id", nullable = false, insertable = false, updatable = false)
    public EDepartment getDeptByDeptId() {
        return deptByDeptId;
    }

    public void setDeptByDeptId(EDepartment deptByDeptId) {
        this.deptByDeptId = deptByDeptId;
    }
}
